﻿using Infrastructure.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Results;
using System.Web.Mvc;

namespace MyWeb.Controllers.Api
{
    public class BaseApiController : ApiController
    {
        // GET api/<controller>
        public BaseApiController()
        {

        }
        protected AjaxResult Try(Action action)
        {
            var result = new AjaxResult();
            try
            {
                action();
            }
            catch (Exception ex)
            {
                result.state = (int)ResultType.error;
                result.message = ex.Message;
            }
            return result;
        }
        protected AjaxResult<T> Try<T>(Action action, AjaxResult<T> result)
        {
            try
            {
                action();
            }
            catch (Exception ex)
            {
                result.state = (int)ResultType.error;
                result.message = ex.Message;
            }
            return result;
        }
    }
}